package com.ruozedata.bigdata.lesson02

import util.control.Breaks._

object LoopApp {

    def main(args: Array[String]): Unit = {

        // 没有break continue
        var x  = 1
        breakable{
            while (x < 20) {
                x += 1

                if (x == 5) {
                    println(5 + "..........")
                    break
                }
            }
        }

        // 使用频率高
        // for
        // 1 to 10  ->  1.to(10)  语法糖
        for (i <- 1 to 10) {  // to [ , ]
            println(i)
        }

        for (i <- 1 until 10) {  // to [ , )
            println(i)
        }

        // 取奇数
        for (i <- 1.to(10, 2)) {
            println(i)
        }

        for (i <- 1 to 10 by 2) {

        }

        for (i <- 1 to 10 reverse) {
            // 反转
        }

        // Range
        println(Range(1, 10, 2))

        // 拓展 加 if
        for (i <- 1 to 10 if i != 8) {
            println(i)
        }

        //for (x <- 1 to 9) {
        //    for (y <- 1 to x) {
        //        print(s"$y * $x = ${x*y} \t")
        //    }
        //    println()
        //}
        for (x <- 1 to 9; y <- 1 to x) {
            print(s"$y * $x = ${x*y} \t")

            if (x == y ) println()
        }

        val res: Seq[Int] = for (x <- 1 to 10) yield x * x
        println(res)

        val res1: String = for (x <- "Scala") yield x.toUpper
        println(res1)

        println("Scala".map(x => x.toUpper).mkString("")) // *****
    }
}
